package com.dl.mall.utils;

import org.junit.Test;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

/**
 * uuid工具类
 */
public class UUIDUtils {

    /**
     * 获取uuid并替换'-'号
     */
    public static String getUUID(){
        return UUID.randomUUID().toString().replaceAll("-","");
    }

    public static String getAppointUUID(int length){
        return getUUID().substring(0,length);
    }

    public static String getUUID5(){
        return getUUID().substring(0,5);
    }

    public static String getUUID8(){
        return getUUID().substring(0,8);
    }

    public static String getUUID10(){
        return getUUID().substring(0,10);
    }

    public static String getUUID16(){
        return getUUID().substring(0,16);
    }

    @Test
    public void test(){
        System.out.println("getUUID() = " + getUUID());
        System.out.println("getUUID5() = " + getUUID5());
        for (int i = 0; i < 10; i++) {
            System.out.println("getAppointUUID(10) = " + getAppointUUID(10));
        }
    }


    @Test
    public void testOrder(){
        long timeMillis = System.currentTimeMillis();
        System.out.println(timeMillis);
        Date date = new Date(timeMillis);
        System.out.println("date = " + date);
/*        for (int i = 0; i < 10; i++) {
            System.out.println("orderId = " + System.currentTimeMillis() + getAppointUUID(3));
        }*/
    }
}
